#/*
# * Copyright {c} 2020-2021, SERI Development Team
# *
# * SPDX-License-Identifier: Apache-2.0
# *
# * Change Logs:
# * Date         Author          Notes
# * 2022-05-22   Lyons           first version
# */

COLORS = "\033[32m"
COLORE = "\033[0m"

PROJDIR = ../..

SIMV = ./simv

CM      = -cm line+cond+fsm+branch+tgl
CM_NAME = -cm_name ${TESTNAME}
CM_DIR  = -cm_dir ${TESTNAME}.vdb

.PHONY: help
help:
	@echo "help       - help menu               "
	@echo "config     - config                  "
	@echo "compile    - compile                 "
	@echo "sim        - simulate                "
	@echo "run        - compile and simulate    "
	@echo "cov        - open coverage           "
	@echo "wave       - open wave               "
	@echo "clean      - clean                   "

.PHONY: config
config:
	@echo -e ${COLORS}[INFO] config environment ...${COLORE}
	${Q}${RM} setup.sh
	${Q}${LINK} ${PROJDIR}/scripts/setup.sh .
	@echo -e ${COLORS}[INFO] execute done${COLORE}

.PHONY: compile
compile:
	@echo -e ${COLORS}[INFO] compile design file ...${COLORE}
	${Q}${VCS} -Mupdate -sverilog +v2k -debug_pp -timescale="1ns/100ps" \
		${ALLDEFINE} ${APPENDCMD} ${WAVEDUMP} ${RTLFILES} ${TBFILES} \
		${CM} ${CM_NAME} ${CM_DIR} -l compile.log
	@echo -e ${COLORS}[INFO] execute done${COLORE}

.PHONY: sim
sim:
	@echo -e ${COLORS}[INFO] vsim run ...${COLORE}
	${Q}../../scripts/createrandom.py > ../../tb/tdata.data
	${Q}${SIMV} ${CM} ${CM_NAME} ${CM_DIR} -l sim.log
	@echo -e ${COLORS}[INFO] execute done${COLORE}

.PHONY: run
run: compile sim

.PHONY: wave_vpd
wave_vpd:
	dve -full64 -vpd wave.vpd &

.PHONY: wave_fsdb
wave_fsdb:
	nWave wave.fsdb &

.PHONY: wave
wave: wave_vpd

.PHONY: cov
cov:
	dve -full64 -covdir *.vdb &

.PHONY: clean
clean:
	@ls | grep -vE "Makefile" | xargs -i rm -rf {}
	@echo -e ${COLORS}[INFO] clean done${COLORE}
